// Copyright 2021 Guoyoko. All Rights Reserved.


#include "Graph/CustomizeFlowGraph.h"
//#include "Asset/SelfAsset.h"
//#include "Node/SelfTaskNode.h"
//#include "Graph/SelfGraphNode.h"
//#include "Graph/SelfGraphNode_Root.h"


namespace SelfGraphHelpers
{

	//void CreateChildren(USelfAsset* SelfAssetObj, USelfTaskNode* RootNode, const UCustomizeFlowGraphNode* RootEdNode, int32 RootIndex = 0)
	//{
	//	if (RootEdNode == nullptr)
	//	{
	//		return;
	//	}
	//	for (int32 PinIdx = 0; PinIdx < RootEdNode->Pins.Num(); PinIdx++)
	//	{
	//		UEdGraphPin* Pin = RootEdNode->Pins[PinIdx];
	//		if (Pin->Direction != EGPD_Output)
	//		{
	//			continue;
	//		}
	//		for (int32 Index = 0; Index < Pin->LinkedTo.Num(); Index++)
	//		{
	//			RootIndex += 1;
	//			UCustomizeFlowGraphNode* GraphNode = Cast<UCustomizeFlowGraphNode>(Pin->LinkedTo[Index]->GetOwningNode());
	//			if (GraphNode == nullptr)
	//			{
	//				continue;
	//			}
	//			USelfTaskNode* TaskInstance = Cast<USelfTaskNode>(GraphNode->NodeInstance);
	//			TaskInstance->AddParentNode(RootNode);
	//			//TaskInstance->SetIndex(RootIndex);
	//			RootNode->AddChildNode(TaskInstance);
	//			CreateChildren(SelfAssetObj, TaskInstance, GraphNode, RootIndex);
	//		}
	//	}
	//}

} // namespace SelfGraphHelpers


void UCustomizeFlowGraph::UpdateAsset(int32 UpdateFlags)
{
	//USelfAsset* SelfAssetObj = Cast<USelfAsset>(GetOuter());
	//if (SelfAssetObj == nullptr)	{ return; }

	////SelfAssetObj->Reset();
	//UCustomizeFlowGraphNode_Root* RootNode = nullptr;
	//for (int32 i = 0; i < Nodes.Num(); i++)
	//{
	//	UCustomizeFlowGraphNode* Node = Cast<UCustomizeFlowGraphNode>(Nodes[i]);
	//	if (Node)
	//	{
	//		USelfTaskNode* NodeInstance = Cast<USelfTaskNode>(Node->NodeInstance);
	//		if (NodeInstance)
	//		{
	//			// mark all nodes as disconnected first, path from root will replace it with valid values later
	//			NodeInstance->Reset();
	//		}
	//	}
	//	if (RootNode == nullptr)
	//	{
	//		RootNode = Cast<UCustomizeFlowGraphNode_Root>(Nodes[i]);
	//	}
	//}

	//if (RootNode)
	//{
	//	UCustomizeFlowGraphNode* RootTaskNode = Cast<UCustomizeFlowGraphNode>(RootNode->GetOutputNode());
	//	if (RootTaskNode)
	//	{
	//		CreateFSFromGraph(RootTaskNode);
	//	}
	//}
}

//void UCustomizeFlowGraph::CreateFSFromGraph(class UCustomizeFlowGraphNode* RootEdNode)
//{
	//USelfAsset* SelfAssetObj = Cast<USelfAsset>(GetOuter());
	//SelfAssetObj->SetRootNode(RootEdNode->NodeInstance);
	//USelfTaskNode* RootTask = Cast<USelfTaskNode>(RootEdNode->NodeInstance);
	//RootTask->Reset();
	//int32 RootIndex = 0;
	////RootTask->SetIndex(RootIndex);
	//SelfGraphHelpers::CreateChildren(SelfAssetObj, RootTask, RootEdNode, RootIndex);
//}

